# # 使用 docker-py 库
# import docker
# import os

# harbor_url = 'http://172.20.216.103:8998'
# repository = 'big_data_image'
# target_image_name = 'test_jupyterlab1'
# version='latest'

# image = os.path.join(harbor_url, repository, target_image_name+':latest')

# # client = docker.from_env()
# # # client.images.build(path='/root/k8s-vue/exam-platform-of-big-data/k8s/student-image', tag=target_image_name)
# # client.images.build(path='/root/k8s-vue/exam-platform-of-big-data/k8s/student-image', tag=target_image_name)

# # client.login(username='admin', password='Harbor12345', registry=harbor_url)
# # client.images.push(repository=image)



# # # 使用 docker 库
# # import docker

# client = docker.DockerClient()
# client.images.build(path='/root/k8s-vue/exam-platform-of-big-data/k8s/student-image/', tag=image)



import docker


def build_image(image_path, tag):

    client = docker.from_env()

    image, build_log = client.images.build(path=image_path, tag=tag)

    return image.id

def run_container(image, command):

    client = docker.from_env()

    container = client.containers.run(image, command)

    return container 
def stop_container(container_id):

    client = docker.from_env()

    container = client.containers.get(container_id)

    container.stop()


def remove_container(container_id):

    client = docker.from_env()

    container = client.containers.get(container_id)

    container.remove() 
if __name__ == '__main__':

    build_image('.', 'test-image') 
    
    # run_container('test-image', 'echo hello world') 
    
    # stop_container('container-id')

    # remove_container('container-id') 
